package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.CateUpdateBoo;
import com.cskaoyan.bean.bo.CategoryCreateBo;
import com.cskaoyan.bean.bo.CategoryDeleteBo;
import com.cskaoyan.bean.bo.CategoryUpdateBo;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CategoryCreateVo;
import com.cskaoyan.bean.vo.CategoryL1Vo;
import com.cskaoyan.bean.vo.CategoryListVo;
import com.cskaoyan.service.CategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:商品类目
 * @Author: chaohe@com.cskaoyan
 * @Date: 2021/7/9
 * @Time: 16:27
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    /**
     * @Author chaohe
     * @description: 品牌制造商的刷新
     * @Date 14:53 2021/7/10
     * url: http://localhost:8083/admin/category/list
     */
    @RequestMapping("/list")
    @RequiresPermissions("admin:category:list")
    public BaseRespVo list() {
        List<CategoryListVo> categoryListVos = categoryService.list();
        return BaseRespVo.ok(categoryListVos);
    }

    /**
     * @Author chaohe
     * @description:会显出一级目录
     * @Date 14:54 2021/7/10
     * url: http://localhost:8083/admin/category/l1
     */
    @RequestMapping("/l1")
    public BaseRespVo l1() {
        List<CategoryL1Vo> categoryL1Vos = categoryService.l1();
        return BaseRespVo.ok(categoryL1Vos);
    }

    /**
     * @Author chaohe
     * @description: 商品类目的删除
     * @Date 14:56 2021/7/10
     * url: http://localhost:8083/admin/category/delete
     */
    @RequestMapping("/delete")
    @RequiresPermissions("admin:category:delete")
    public BaseRespVo delete(@RequestBody CategoryDeleteBo categoryDeleteBo) {
        categoryService.delete(categoryDeleteBo);
        return BaseRespVo.ok();
    }

    /**
     * @Author chaohe
     * @description: 商品类目的更新
     * @Date 14:56 2021/7/10
     * url:    http://localhost:8083/admin/category/update
     */
    @RequestMapping("/update")
    @RequiresPermissions("admin:category:update")
    public BaseRespVo update(@RequestBody CategoryUpdateBo categoryUpdateBo) {
        categoryService.update(categoryUpdateBo);
        return BaseRespVo.ok();
    }
    /**
     * @Author chaohe
     * @description: 商品类目的添加
     * @Date 14:56 2021/7/10
     * url: http://localhost:8083/admin/category/create
     */

    @RequestMapping("/create")
    @RequiresPermissions("admin:category:create")
    public BaseRespVo create(@RequestBody CategoryCreateBo categoryCreateBo) {
        CategoryCreateVo categoryCreateVo = categoryService.create(categoryCreateBo);
        return BaseRespVo.ok(categoryCreateVo);
    }


}

